<gm:page title="My App" authenticate="true">

  <script>
    
    var initial = false;
    
    function onSearch()
    {
       var list1 = google.mashups.getObjectById("list1");
       list1.setData("http://www.heise.de/autos/rss/news-atom.xml");
    }
    
    function clearList(list)
    {
      var num = list.size();
      var i;
      for (i=num-1;i>=0;i-=1)
      {
        var entry = list.entryAt(i);
        list.removeEntry(entry);
      }
    }    

    function onCopy()
    {
       var list1 = google.mashups.getObjectById("list1").getData();    
       var list2 = google.mashups.getObjectById("list2").getData();
    
       clearList(list2);
       
       for (var i=0;i<list1.size() && (i<10);i++)
       {
          var entry = list1.entryAt(i);
          list2.addEntry(GPath.cloneEntry(entry));
       }
       switchToApp();
    }

    function onClear()
    {
       var list2 = google.mashups.getObjectById("list2").getData();
       clearList(list2);
       onSearch();
    }
    
    function switchToApp()
    {
       var list1 = google.mashups.getObjectById("list1")
       list1.setData("${app}/temp_storage");
    }
    
    function repaintApp()
    {
       var list1 = google.mashups.getObjectById("list1");           
       var list2 = google.mashups.getObjectById("list2").getData();        
       var list1d = list1.getData();           
       var str = list1d._.f.toString();
       if (str.match("BlankQuery"))
       {

         if (list2.size()>0)
            list1.setData("${app}/temp_storage");
         else
            list1.setData("http://www.heise.de/autos/rss/news-atom.xml");
       }
       document.getElementById("clearButton").disabled = (list2.size()==0);
    }
    
            
  </script>

  <input type="button" value="Search" onclick="onSearch();" />  
  <input type="button" value="Copy" onclick="onCopy();" />    
  <input id="clearButton" type="button" value="Clear" disabled=true onclick="onClear();" />    
      
  <gm:list id="list1" template="default"/>
  <hr/>
  <gm:list id="list2" data="${app}/temp_storage" template="default" style="display:none">
    <gm:handleEvent event="repaint" execute="repaintApp();"/>
  </gm:list>
  
</gm:page>